package com.tokenplus.thai.aviewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.tokenplus.thai.adata.home.getInviteFriendEarn.ReqGetInviteFriendEarn
import com.tokenplus.thai.adata.home.getInviteIncomeList.RevDataGetInviteIncomeList
import com.tokenplus.thai.adata.home.getTransferInEarn.RevDataGetTransferInEarn
import com.tokenplus.thai.adata.home.getTransferInEarnList.RevDataGetTransferInEarnList
import com.tokenplus.thai.adata.home.getTransferInExtractList.RevDataGetTransferInExtractList
import com.tokenplus.thai.base.BaseViewModel
import com.tokenplus.thai.anetwork.ApiUserReposity
import com.tokenplus.thai.data.ReqBase
import com.tokenplus.thai.earn.adapter.EarnLevelPageAdapter
import com.tokenplus.thai.utils.CalendarUtil
import com.tokenplus.thai.utils.SpUtil

class HomeViewModel : BaseViewModel() {

    private val mGetInviteFriendEarnLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val onGetInviteFriendEarnLiveData =
        Transformations.switchMap(mGetInviteFriendEarnLiveData) { query ->
            ApiUserReposity.getInviteFriendEarn(this, query)
        }

    fun getInviteFriendEarn(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetInviteFriendEarnLiveData.value = reqGetInviteFriendEarn
    }

    //////////////////////////////////////////
    private val mGetInviteIncomeListLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val mGetInviteIncomeList = mutableListOf<RevDataGetInviteIncomeList>()

    val onGetInviteIncomeListLiveData =
        Transformations.switchMap(mGetInviteIncomeListLiveData) { query ->
            ApiUserReposity.getInviteIncomeList(this, query)
        }

    fun getInviteIncomeList(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetInviteIncomeListLiveData.value = reqGetInviteFriendEarn
    }

    //////////////////////////////////////////
    private val mGetTransferInDetailLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val onGetTransferInDetailLiveData =
        Transformations.switchMap(mGetTransferInDetailLiveData) { query ->
            ApiUserReposity.getTransferInDetail(this, query)
        }

    fun getTransferInDetail(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetTransferInDetailLiveData.value = reqGetInviteFriendEarn
    }

    //////////////////////////////////////////
    val mTransferInEarnList = mutableListOf(
        RevDataGetTransferInEarn(
            isValidData = false,
            level = EarnLevelPageAdapter.LEVEL_BRONZE,
            incomeRate = "0.02",
            nextAmount = "500"
        ),
        RevDataGetTransferInEarn(
            isValidData = false,
            level = EarnLevelPageAdapter.LEVEL_GOLD,
            incomeRate = "0.025",
            nextAmount = "500+"
        ),
        RevDataGetTransferInEarn(
            isValidData = false,
            level = EarnLevelPageAdapter.LEVEL_PLATINUM,
            incomeRate = "0.03",
            nextAmount = "10000"
        ),
        RevDataGetTransferInEarn(
            isValidData = false,
            level = EarnLevelPageAdapter.LEVEL_DIAMOND,
            incomeRate = "0.035",
            nextAmount = "10000+"
        )
    )

    private val mGetTransferInEarnLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val onGetTransferInEarnLiveData =
        Transformations.switchMap(mGetTransferInEarnLiveData) { query ->
            ApiUserReposity.getTransferInEarn(this, query)
        }

    fun getTransferInEarn(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetTransferInEarnLiveData.value = reqGetInviteFriendEarn
    }

    //////////////////////////////////////////
    private val mGetTransferInEarnListLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val mGetTransferInEarnList = mutableListOf<RevDataGetTransferInEarnList>()

    val onGetTransferInEarnListLiveData =
        Transformations.switchMap(mGetTransferInEarnListLiveData) { query ->
            ApiUserReposity.getTransferInEarnList(this, query)
        }

    fun getTransferInEarnList(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetTransferInEarnListLiveData.value = reqGetInviteFriendEarn
    }

    //////////////////////////////////////////
    private val mGetTransferInExtractListLiveData = MutableLiveData<ReqGetInviteFriendEarn>()

    val mGetTransferInExtractList = mutableListOf<RevDataGetTransferInExtractList>()

    val onGetTransferInExtractListLiveData =
        Transformations.switchMap(mGetTransferInExtractListLiveData) { query ->
            ApiUserReposity.getTransferInExtractList(this, query)
        }

    fun getTransferInExtractList(reqGetInviteFriendEarn: ReqGetInviteFriendEarn) {
        mGetTransferInExtractListLiveData.value = reqGetInviteFriendEarn
    }

}